<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p class="time"></p>

    <script>
        var nowTime = new Date().getTime()
        // console.log(nowTime);

        var date = new Date('2023-10-1').getTime()
        // console.log(date);

        var time = parseInt((date - nowTime) / 1000)
        console.log(time);

        var timer

        function setTime() {
            time--
            var d = parseInt(time / 60 / 60 / 24)
            var h = parseInt(time / 60 / 60 % 24)
            var m = parseInt(time / 60 % 60)
            var s = parseInt(time % 60)


            h = h < 10 ? '0' + h : h
            m = m < 10 ? '0' + m : m
            s = s < 10 ? '0' + s : s

            document.querySelector('.time').innerHTML = `距离2023年国庆还有${d}天:${h}时${m}分${s}秒`


            if (time <= 0) {
                clearInterval(timer)
            }



        }
        setTime()

        timer = setInterval(setTime, 1000)


    </script>
</body>

</html>